#include "Acceptor.h"

Acceptor::Acceptor(EventLoop *loop, const std::string &ip, const uint16_t& port)
:loop_(loop)
{
    servsock_ = new Socket(createnonblocking());
    InetAddress serveraddr(ip, port);
    servsock_->setkeepalive(true);
    servsock_->setreuseaddr(true);
    servsock_->setreuseport(true);
    servsock_->settcpnodelay(true);
    servsock_->bind(serveraddr);
    servsock_->listen();
    std::vector<epoll_event> evs;

    // int epfd = epoll_create(1);
    // Epoll epoll;
    acceptchannel_ = new Channel(loop_->getEpfd(), servsock_->fd());
    acceptchannel_->setreadcallback(std::bind(&Channel::newConnection, acceptchannel_, servsock_));
    acceptchannel_->enablereading();
    acceptchannel_->setinepoll();
}

Acceptor::~Acceptor()
{
    delete servsock_;
    delete acceptchannel_;
}